﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections.ObjectModel;
using University.Workshop.Model;
using University.Workshop.Business;
using University.Workshop.DataAccess;

namespace University.Workshop.WebApp
{
    public partial class ViewOffers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            Collection<Offer> offerList = new Collection<Offer>();
            Collection<ProductAuction> prod = new Collection<ProductAuction>();
            Collection<ProductAuction> list = new Collection<ProductAuction>();
            User user = UserDataAccess.GetUserByEmail(User.Identity.Name);
            prod = AuctionDataAccess.AllAuctions();
            if (prod != null)
            {
                foreach (var item in prod)
                {
                    if (item.Auction.BidderUserId == user.Id && item.Auction.Date <= DateTime.Now)
                    {
                        list.Add(item);
                    }

                }
            } 
            offerList = OfferManager.GetOffersByBuyerId(user.Id);
            if (offerList != null)
            {
                if (!IsPostBack)
                {
                    dlWatchList.DataSource = offerList;
                    dlWatchList.DataBind();
                }
            }
            else
                Label3.Visible = true;
            if (list != null)
            {
                if (!IsPostBack)
                {
                    dlWatchList0.DataSource = list;
                    dlWatchList0.DataBind();
                }
                else 
                {
                    Label5.Visible=true;
                }
            }

        }

    }
}